<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
      <title>GTL - Graph Template Library: bellman_ford.h Source File</title>
      <link href="doxygen.css" rel="stylesheet" type="text/css">
  </head>
  <body>
    <p class="links">  
      <a href="../index.html">Home</a> |
      Documentation |
      <a href="../register.html">Download</a> |
      <a href="../platforms.html">Platforms</a> |
      <a href="../refer.html">Projects</a> |      
      <a href="../lists.html">Mailing Lists</a> |
      <a href="../history.html">Version History</a>
    </p>

<!-- Generated by Doxygen 1.5.3 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="classes.html"><span>Classes</span></a></li>
    <li class="current"><a href="files.html"><span>Files</span></a></li>
    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
  </ul>
</div>
<h1>bellman_ford.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">//==========================================================================</span>
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">//   bellman_ford.h</span>
<a name="l00004"></a>00004 <span class="comment">//</span>
<a name="l00005"></a>00005 <span class="comment">//==========================================================================</span>
<a name="l00006"></a>00006 <span class="comment">// $Id: bellman_ford.h,v 1.5 2003/03/24 15:58:54 raitner Exp $ </span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="preprocessor">#ifndef GTL_BELLMAN_FORD_H</span>
<a name="l00009"></a>00009 <span class="preprocessor"></span><span class="preprocessor">#define GTL_BELLMAN_FORD_H</span>
<a name="l00010"></a>00010 <span class="preprocessor"></span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;GTL/GTL.h&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;GTL/algorithm.h&gt;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;GTL/node_map.h&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;GTL/edge_map.h&gt;</span>
<a name="l00015"></a>00015 
<a name="l00016"></a>00016 __GTL_BEGIN_NAMESPACE
<a name="l00017"></a>00017 
<a name="l00018"></a>00018 
<a name="l00032"></a><a class="code" href="a00002.html">00032</a> <span class="keyword">class </span>GTL_EXTERN <a class="code" href="a00002.html" title="Bellman Ford algorithm.">bellman_ford</a> : <span class="keyword">public</span> <a class="code" href="a00001.html" title="Abstract baseclass for all algoritm-classes.">algorithm</a> 
<a name="l00033"></a>00033 {
<a name="l00034"></a>00034 <span class="keyword">public</span>:
<a name="l00035"></a>00035 
<a name="l00039"></a>00039     <a class="code" href="a00002.html" title="Bellman Ford algorithm.">bellman_ford</a>();
<a name="l00040"></a>00040 
<a name="l00044"></a>00044     <span class="keyword">virtual</span> ~<a class="code" href="a00002.html" title="Bellman Ford algorithm.">bellman_ford</a>();
<a name="l00045"></a>00045 
<a name="l00057"></a>00057     <span class="keywordtype">int</span> <a class="code" href="a00001.html#76361fb03ad1cf643affc51821e43bed" title="Checks whether all preconditions are satisfied.">check</a> (<a class="code" href="a00014.html" title="A directed or undirected graph.">graph</a>&amp; G);
<a name="l00058"></a>00058 
<a name="l00059"></a>00059     <span class="keywordtype">int</span> <a class="code" href="a00001.html#734b189509a8d6b56b65f8ff772d43ca" title="Applies algorithm to graph g.">run</a> (<a class="code" href="a00014.html" title="A directed or undirected graph.">graph</a>&amp; G);
<a name="l00060"></a>00060 
<a name="l00067"></a>00067     <span class="keywordtype">void</span> <a class="code" href="a00001.html#21aba63d066ae7897de6ca7d8425c408" title="Resets algorithm.">reset</a> ();
<a name="l00068"></a>00068 
<a name="l00078"></a><a class="code" href="a00002.html#98cad540fd2d211c1ba44bb6fa8416f3">00078</a>     <span class="keywordtype">void</span> source (<span class="keyword">const</span> <a class="code" href="a00020.html" title="A node in a graph.">node</a>&amp; n) {s = n;}    
<a name="l00079"></a>00079 
<a name="l00085"></a><a class="code" href="a00002.html#d0cf03b1e57fc0e96ce46f772519e5b2">00085</a>     <a class="code" href="a00020.html" title="A node in a graph.">node</a> source ()<span class="keyword"> const </span>{<span class="keywordflow">return</span> s;}
<a name="l00086"></a>00086 
<a name="l00094"></a><a class="code" href="a00002.html#9e276cc9f30c2e608d320db4a08b2a74">00094</a>     <span class="keywordtype">void</span> weights (<span class="keyword">const</span> <a class="code" href="a00011.html" title="A specialized map with edges as keys.">edge_map&lt;double&gt;</a>&amp; weight) {w = weight; vars_set = <span class="keyword">true</span>; }
<a name="l00095"></a>00095     
<a name="l00106"></a>00106     <span class="keywordtype">void</span> store_preds (<span class="keywordtype">bool</span> <span class="keyword">set</span>);
<a name="l00107"></a>00107 
<a name="l00116"></a><a class="code" href="a00002.html#46385105a5c73d364cc92276ddd8daa1">00116</a>     <span class="keywordtype">bool</span> store_preds ()<span class="keyword"> const </span>{<span class="keywordflow">return</span> preds != 0;}
<a name="l00117"></a>00117 
<a name="l00123"></a><a class="code" href="a00002.html#48fd2ed9748bdafeb61e5bb296ec67c6">00123</a>     <span class="keywordtype">bool</span> reached (<span class="keyword">const</span> <a class="code" href="a00020.html" title="A node in a graph.">node</a>&amp; n)<span class="keyword"> const </span>{<span class="keywordflow">return</span> !inf[n];}
<a name="l00124"></a>00124 
<a name="l00130"></a><a class="code" href="a00002.html#30203c9433e4fb628e6d5d86e2c81d5c">00130</a>     <span class="keywordtype">double</span> distance (<span class="keyword">const</span> <a class="code" href="a00020.html" title="A node in a graph.">node</a>&amp; n)<span class="keyword"> const </span>{<span class="keywordflow">return</span> d[n];}
<a name="l00131"></a>00131 
<a name="l00146"></a><a class="code" href="a00002.html#ec75a9280a8e108b59f5f0294e4bdff0">00146</a>     <a class="code" href="a00010.html" title="An edge in a graph.">edge</a> predecessor_edge (<span class="keyword">const</span> <a class="code" href="a00020.html" title="A node in a graph.">node</a>&amp; n)<span class="keyword"> const</span>
<a name="l00147"></a>00147 <span class="keyword">        </span>{assert (preds); <span class="keywordflow">return</span> (*preds)[n];}
<a name="l00148"></a>00148 
<a name="l00163"></a><a class="code" href="a00002.html#3122381284e811ef02b7061d383eecb7">00163</a>     <a class="code" href="a00020.html" title="A node in a graph.">node</a> predecessor_node (<span class="keyword">const</span> <a class="code" href="a00020.html" title="A node in a graph.">node</a>&amp; n)<span class="keyword"> const</span>
<a name="l00164"></a>00164 <span class="keyword">        </span>{<a class="code" href="a00010.html" title="An edge in a graph.">edge</a> e = predecessor_edge(n); <span class="keywordflow">return</span> e == <a class="code" href="a00010.html" title="An edge in a graph.">edge</a>() ? <a class="code" href="a00020.html" title="A node in a graph.">node</a>() : e.<a class="code" href="a00010.html#4a02e493cf05a2295f6eec47eb1498f3">opposite</a>(n); }
<a name="l00165"></a>00165 
<a name="l00170"></a><a class="code" href="a00002.html#2dd5b35844eeb4ca3e57f42d57975ebe">00170</a>     <span class="keywordtype">bool</span> negative_cycle()<span class="keyword"> const</span>
<a name="l00171"></a>00171 <span class="keyword">        </span>{<span class="keywordflow">return</span> cycle;}
<a name="l00172"></a>00172 
<a name="l00173"></a>00173 <span class="keyword">private</span>:
<a name="l00174"></a>00174 
<a name="l00175"></a>00175     
<a name="l00181"></a>00181     <span class="keywordtype">void</span> relax (<span class="keyword">const</span> <a class="code" href="a00010.html" title="An edge in a graph.">edge</a>&amp; e, <span class="keywordtype">bool</span> dir);
<a name="l00182"></a>00182 
<a name="l00188"></a>00188     <a class="code" href="a00020.html" title="A node in a graph.">node</a> s;
<a name="l00189"></a>00189 
<a name="l00195"></a>00195     <a class="code" href="a00011.html" title="A specialized map with edges as keys.">edge_map&lt;double&gt;</a> w;
<a name="l00196"></a>00196     
<a name="l00202"></a>00202     <span class="keywordtype">bool</span> vars_set; 
<a name="l00203"></a>00203 
<a name="l00209"></a>00209     <a class="code" href="a00021.html" title="A specialized map with nodes as keys.">node_map&lt;double&gt;</a> d; 
<a name="l00210"></a>00210 
<a name="l00216"></a>00216     <a class="code" href="a00021.html" title="A specialized map with nodes as keys.">node_map&lt;bool&gt;</a> inf;
<a name="l00217"></a>00217 
<a name="l00223"></a>00223     <a class="code" href="a00021.html" title="A specialized map with nodes as keys.">node_map&lt;edge&gt;</a>* preds;
<a name="l00224"></a>00224 
<a name="l00231"></a>00231     <span class="keywordtype">bool</span> cycle; 
<a name="l00232"></a>00232 };
<a name="l00233"></a>00233 
<a name="l00234"></a>00234 __GTL_END_NAMESPACE
<a name="l00235"></a>00235 
<a name="l00236"></a>00236 <span class="preprocessor">#endif // GTL_BELLMAN_FORD_H</span>
</pre></div>    <p class="links">
      <a href="http://www.uni-passau.de/">University of Passau</a>
      &nbsp;-&nbsp;
      <a href="http://www.fmi.uni-passau.de/">FMI</a>
      &nbsp;-&nbsp;
      <a href="http://www.fmi.uni-passau.de/fmi/lehrstuehle/brandenburg/">Theoretical
	Computer Science</a>
    </p>
  <div class="copyright">
      Design &copy; 2002, 2003 <a href="mailto:raitner@fmi.uni-passau.de">Marcus Raitner</a>,  University of Passau 
  </div>
</body>
</html>
